package javaCode.chapter06.本章作业;

import java.util.Random;
import java.util.Scanner;

public class MoraGame { //扩展题

    public static void main(String[] args) {

//        Tom t = new Tom();
//        int len = 10;
//        int[] arr = new int[len];
//        Random r = new Random();
//        for (int i = 0; i < len; i++) {
//            int ran = r.nextInt(3);
//            arr[i] = ran;
//        }
//
//        t.t(arr);

        Scanner myScanner = new Scanner(System.in);
        int len = 5;
        Tom t = new Tom(len);

        System.out.println("请输入你的数字(0-石头,1-剪刀,2-布)，1号表示电脑 2号表示tom");

        for (int i = 0; i < len; i++) {
            int num = myScanner.nextInt();
            t.t2(num);
        }

    }
}

/*
有个人 Tom 设计他的成员变量.成员方法，可以电脑猜拳
电脑每次都会随机生成0,1,2
0表示 石头 1表示剪刀 2表示布
并可以显示 Tom的输赢次数 (清单)
 */

class Tom {
    int computer;
    int len;


    public Tom(int len) {
        this.len = len;
    }

    public void t1(int[] person) {
        Random r = new Random();
        System.out.println("电脑 \tTom");
        String str = "Tom胜"; //省略代码数量
        int count = 0;  //计算电脑赢的次数
        int draw = 0; //计算平局的次数

        for (int i = 0; i < person.length; i++) {
            int ran = r.nextInt(3);
            computer = ran;
            int p = person[i];

            if (computer == 0 && person[i] == 2) {

                System.out.println(show() + p + " \t" + str);
            } else if (computer == 1 && person[i] == 0) {

                System.out.println(show() + p + " \t" + str);
            } else if (computer == 2 && person[i] == 1) {

                System.out.println(show() + p + " \t" + str);
            } else if (computer == person[i]) {
                draw++;
                System.out.println(show() + p + " \t平局");
            } else {
                count++;
                System.out.println(show() + p + " \t电脑胜");
            }
        }

        System.out.println("电脑赢了 " + count + "次  " + "Tom赢了" + (person.length - count - draw) + "次" + " 平局了 " + draw);
    }

    public void t2(int p) {
        Random r = new Random();
        System.out.println("电脑 \tTom");
        String str = "Tom胜"; //省略代码数量

        int count = 0; //计算电脑赢的次数
        int draw = 0; //计算平局的次数
        int xx = 0; //计算tom赢的次数

        int ran = r.nextInt(3);
        computer = ran;

        if (computer == 0 && p == 2) {
            xx++;
            System.out.println(show() + p + " \t" + str);
        } else if (computer == 1 && p == 0) {
            xx++;
            System.out.println(show() + p + " \t" + str);
        } else if (computer == 2 && p == 1) {
            xx++;
            System.out.println(show() + p + " \t" + str);
        } else if (computer == p) {
            draw++;
            System.out.println(show() + p + " \t平局");
        } else {
            count++;
            System.out.println(show() + p + " \t电脑胜");
        }

    }

    public String show() {
        return (computer + " \t\t"); //省略代码数量
    }

    public void Print(){

    }
}